﻿using Essensoft.Paylink.Alipay.Domain;
using Health.Code;
using Health.Domain;
using Health.Infrastructure.Interface;
using Health.WebAPI.Read.Applicant.Command;
using MediatR;

namespace Health.WebAPI.Read.Applicant.CommandHandler
{
    /// <summary>
    ///
    /// </summary>
    public class ShowColmunCommandHandler : IRequestHandler<ShowColmunCommand, APIRestl<List<Column>>>
    {
        IBaseRepository<Column> columnRep;

        public ShowColmunCommandHandler(IBaseRepository<Column> columnRep)
        {
            this.columnRep = columnRep;
        }

        public Task<APIRestl<List<Column>>> Handle(ShowColmunCommand request, CancellationToken cancellationToken)
        {
            APIRestl<List<Column>> restl= new APIRestl<List<Column>>();
            restl.code = APIEnum.显示成功;
            restl.mes = APIEnum.显示成功.ToString();

            var list = columnRep.GetAll();

            if (!string.IsNullOrEmpty(request.ColumnName))
            {
                list=list.Where(s=>s.ColumnName.Contains(request.ColumnName));
            }

            restl.data = list.ToList();

            return Task.FromResult(restl);
        }
    }
}